package com.example.teacher;

import android.content.Intent;
import android.os.Bundle;

import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.database.DatabaseHelper;
import com.example.function.CourseFunction;
import com.example.function.StaffFunction;
import com.example.function.StudentFunction;
import com.example.student.R;


public class HomeFragment extends Fragment {
    private Integer teacherId = -1;

    private DatabaseHelper databaseHelper;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        databaseHelper = new DatabaseHelper(getActivity());
        // 获取当前教师的 ID（假设从 Activity 传递过来）
        Bundle bundle = getArguments();
        if (bundle != null) {
            teacherId = bundle.getInt("teacher_id", -1);
        }
        // 找到 CardView
        CardView cardAddStudent = view.findViewById(R.id.cardStudent);
        CardView cardAddStaff = view.findViewById(R.id.cardStaff);
        CardView cardAddCourse = view.findViewById(R.id.cardCourse);

        // 设置点击事件
        cardAddStudent.setOnClickListener(v -> gotoNavigate(StudentFunction.class));
        cardAddStaff.setOnClickListener(v -> gotoNavigate(StaffFunction.class));
        cardAddCourse.setOnClickListener(v -> gotoNavigate(CourseFunction.class));
        return view;
    }

    /**
     * @param targetActivity 目标 Activity
     */
    private void gotoNavigate(Class<?> targetActivity) {
        Intent intent = new Intent(getActivity(), targetActivity);
        startActivity(intent);
    }
}